package com.gis507.test.AisTest3;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 1、声明属性  4个
 * 2、继承Writable，重写序列化和反序列化方法
 */
public class AisBean implements Writable {

    private double speed;
    private Long unixTime;
    private double lon_d;
    private double lat_d;

    public AisBean() {
    }

    public AisBean(double speed, Long unixTime, double lon_d, double lat_d) {
        this.speed = speed;
        this.unixTime = unixTime;
        this.lon_d = lon_d;
        this.lat_d = lat_d;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public Long getUnixTime() {
        return unixTime;
    }

    public void setUnixTime(Long unixTime) {
        this.unixTime = unixTime;
    }

    public double getLon_d() {
        return lon_d;
    }

    public void setLon_d(double lon_d) {
        this.lon_d = lon_d;
    }

    public double getLat_d() {
        return lat_d;
    }

    public void setLat_d(double lat_d) {
        this.lat_d = lat_d;
    }

    @Override
    public String toString() {
        return speed + "," + unixTime + "," + lon_d + "," + lat_d;
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {

        dataOutput.writeDouble(speed);
        dataOutput.writeLong(unixTime);
        dataOutput.writeDouble(lon_d);
        dataOutput.writeDouble(lat_d);

    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {

        this.speed = dataInput.readDouble();
        this.unixTime = dataInput.readLong();
        this.lon_d = dataInput.readDouble();
        this.lat_d = dataInput.readDouble();
    }
}
